package com.cqeec.myblog.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sun.org.apache.xml.internal.security.Init;

public class PageBean<E> {
	private Map<String, Object> data=new HashMap<>();
	
	//当前页数(默认为1)
	private int curPage=1;
	//总的记录数
	private int pageRecordCount;
	//数据集合
	private List<E> list;
	//访问网址
	private String url;
	
	
	//起始按钮数字锁
	private boolean start_flag=true;
	//终结按钮数字锁
	private boolean end_flag=true;
	
	//左偏移量
	private int offset_left=5;
	//右偏移量
	private int offset_right=4;
	//每页最大显示1条数据
	private int pageSize=2;
	
    
    //开始按钮数字
    private int startPageButton;
    //结束按钮数字
    private int endPageButton;
        
    public void calculationNumBtn(){
    	if(end_flag) {
			//定义分页终结按钮的初始数字
			setEndPageButton(curPage+offset_right);
			if(getPageNumber()>10) {
	                if(endPageButton>getPageNumber()) {
	                	//重新赋值结束按钮数字为总页数
	                	setEndPageButton(getPageNumber());
	                	//将右偏移量缺失值补给左偏移量
	                	int right_missingValue=curPage+offset_right-getPageNumber();
	                	setStartPageButton(curPage-offset_left-right_missingValue);
	                	start_flag=false;
	                }
			}else {
				setEndPageButton(getPageNumber());
			}
		}
         if(start_flag) {
			//定义分页起始按钮的初始数字（可能为负数）
			setStartPageButton(curPage-offset_left);
			if(getPageNumber()>10) {
				   //如果起始按钮数字小于1
				   if(startPageButton<1) {
					   //重新赋值起始按钮数字为1
					   setStartPageButton(1);
					   //将左偏移量缺失值补给右偏移量
					   int left_missingValue=Math.abs(curPage-offset_left-1);
					   setEndPageButton(curPage+offset_right+left_missingValue);
					   end_flag=false;
				   }
			}else {
				setStartPageButton(1);
			}
		}
    }
    

	public Map<String, Object> getData() {
		return data;
	}


	public void setData(Map<String, Object> data) {
		this.data = data;
	}


	public String getUrl() {
		return url;
	}


	public void setUrl(String url) {
		this.url = url;
	}


	public int getOffset_left() {
		return offset_left;
	}
	public void setOffset_left(int offset_left) {
		this.offset_left = offset_left;
	}
	public int getOffset_right() {
		return offset_right;
	}
	public void setOffset_right(int offset_right) {
		this.offset_right = offset_right;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getCurPage() {
		return curPage;
	}
	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}
	public int getPageRecordCount() {
		return pageRecordCount;
	}
	public void setPageRecordCount(int pageRecordCount) {
		this.pageRecordCount = pageRecordCount;
	}
	
	
	public int getPageNumber() {
		//根据总的记录数以及每页显示的最大记录数
		//计算出总页数
		int pageNumber
		=pageRecordCount%pageSize==0
		?pageRecordCount/pageSize
		:pageRecordCount/pageSize+1;
		return pageNumber;
	}
	
	
	
	public List<E> getList() {
		return list;
	}
	public void setList(List<E> list) {
		this.list = list;
	}
	public int getStartPageButton() {
		return startPageButton;
	}
	public void setStartPageButton(int startPageButton) {
		this.startPageButton = startPageButton;
	}
	public int getEndPageButton() {
		return endPageButton;
	}
	public void setEndPageButton(int endPageButton) {
		this.endPageButton = endPageButton;
	}
	
    
	
}
